function err_exit {
    echo "----Install Error: $1 -----------"
    exit 1
}

# php install function
function composer_vendor_ins {

    # 源码包路径
    srcPath=$1
    if [ ! -f "$srcPath" ]; then
        err_exit "not found source package."
    fi

    # 检测是否.tar.gz后缀
    srcName=${srcPath##*/}
    packageName=${srcName/%.tar.gz/}
    if [ "$srcName"x = "$packageName"x ];then
        err_exit "not found .tar.gz file."
    fi
    packageName=`tar -tf ${srcPath} |head -n 1`
    packageName=${packageName/%\/*}

    # 源码包路径
    srcDir=${srcPath%/*}

    # 程序名(没版本号)
    pkgName=${packageName}

    #todo 获取安装目录
    installPath=${2:-"/usr/local/${packageName}"}

    # 日志路径
    IN_LOG=/tmp/${pkgName}_install.log
    echo "">$IN_LOG
    if [ "$?" != "0" ]; then
        err_exit "create log file."
    fi

    echo
    echo "$packageName installing..."

    # 进入源码包目录
    cd $srcDir

    # 清除文件
    rm -Rf $packageName

    # 解压源码包
    tar -zxvf $srcPath > $IN_LOG 2>&1
    cd $packageName

    # 拷贝源码
    mkdir -p $installPath

    cp -Rf * $installPath/ >> $IN_LOG 2>&1
    if [ "$?" != "0" ]; then
        err_exit "$packageName install err"
    fi

    # .compoer目录权限更新
    chmod -R 755 $installPath
    chmod -R 777 $installPath/cache

    # 清除源码包目录
    cd $srcDir
    rm -Rf $packageName

    echo "$packageName complete."
}

composer_vendor_ins $*
